package com.shujia

object Code07Fun {
  def main(args: Array[String]): Unit = {

    fun1(fun)
    fun1(fun2)
    // 以函数作为参数时，只要满足函数类型，那么就可以将其他函数进行传递

    println(fun3(fun4,10,20))
    println(fun3(fun5,b = 10,a=20))
  }

  def fun(): Unit = {
    println("this is fun")
  }

  def fun2(): Unit = {
    println("this is fun2")
  }

  def fun1(f: () => Unit): Unit = {
    f()
  }


  def fun3(f: (Int, Int) => Int, a: Int, b: Int): Int = {
    f(a, b)
  }

  def fun4(c: Int, b: Int): Int = {
    c + b
  }

  def fun5(c: Int, b: Int): Int = {
    c * b
  }

}
